{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "67af3c0b",
   "metadata": {},
   "source": [
    "# 实践：宿舍人脸识别门禁系统\n",
    "\n",
    "> 1. 创建FaceSet\n",
    "> 2. 查询FaceSet\n",
    "> 3. 存入face_token数据\n",
    "> 4. 获取FaceSet信息数据\n",
    "> 5. 人脸搜索\n",
    "> 6. 人脸对比\n",
    "\n",
    "-----"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "edc4ed4b",
   "metadata": {},
   "source": [
    "## 创建人脸库 API\n",
    "\n",
    "* 描述\n",
    "> 创建一个人脸的集合 FaceSet，用于存储人脸标识 face_token。一个 FaceSet 能够存储10000个 face_token。试用API Key可以创建1000个FaceSet，正式API Key可以创建10000个FaceSet。\n",
    "\n",
    "* URL\n",
    "> https://api-cn.faceplusplus.com/facepp/v3/faceset/create"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "901ac9c3",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "8f5232bf",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>是否必选</th>\n",
       "      <th>参数名</th>\n",
       "      <th>类型</th>\n",
       "      <th>参数说明</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>必选</td>\n",
       "      <td>api_key</td>\n",
       "      <td>String</td>\n",
       "      <td>调用此 API 的 API Key</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>必选</td>\n",
       "      <td>api_secret</td>\n",
       "      <td>String</td>\n",
       "      <td>调用此 API 的 API Secret</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>可选</td>\n",
       "      <td>display_name</td>\n",
       "      <td>String</td>\n",
       "      <td>人脸集合的名字，最长256个字符，不能包括字符^@,&amp;=*'\"</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>可选</td>\n",
       "      <td>outer_id</td>\n",
       "      <td>String</td>\n",
       "      <td>账号下全局唯一的 FaceSet 自定义标识，可以用来管理 FaceSet 对象。最长255...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>可选</td>\n",
       "      <td>tags</td>\n",
       "      <td>String</td>\n",
       "      <td>FaceSet 自定义标签组成的字符串，用来对 FaceSet 分组。最长255个字符，多个...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>可选</td>\n",
       "      <td>face_tokens</td>\n",
       "      <td>String</td>\n",
       "      <td>人脸标识 face_token，可以是一个或者多个，用逗号分隔。最多不超过5个 face_t...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>可选</td>\n",
       "      <td>user_data</td>\n",
       "      <td>String</td>\n",
       "      <td>自定义用户信息，不大于16 KB，不能包括字符^@,&amp;=*'\"</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>可选</td>\n",
       "      <td>force_merge</td>\n",
       "      <td>Int</td>\n",
       "      <td>在传入 outer_id 的情况下，如果 outer_id 已经存在，是否将 face_to...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  是否必选           参数名      类型  \\\n",
       "0   必选       api_key  String   \n",
       "1   必选    api_secret  String   \n",
       "2   可选  display_name  String   \n",
       "3   可选      outer_id  String   \n",
       "4   可选          tags  String   \n",
       "5   可选   face_tokens  String   \n",
       "6   可选     user_data  String   \n",
       "7   可选   force_merge     Int   \n",
       "\n",
       "                                                参数说明  \n",
       "0                                  调用此 API 的 API Key  \n",
       "1                               调用此 API 的 API Secret  \n",
       "2                    人脸集合的名字，最长256个字符，不能包括字符^@,&=*'\"  \n",
       "3  账号下全局唯一的 FaceSet 自定义标识，可以用来管理 FaceSet 对象。最长255...  \n",
       "4  FaceSet 自定义标签组成的字符串，用来对 FaceSet 分组。最长255个字符，多个...  \n",
       "5  人脸标识 face_token，可以是一个或者多个，用逗号分隔。最多不超过5个 face_t...  \n",
       "6                    自定义用户信息，不大于16 KB，不能包括字符^@,&=*'\"  \n",
       "7  在传入 outer_id 的情况下，如果 outer_id 已经存在，是否将 face_to...  "
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.read_html(\"\"\"<div class=\"table-wrap\"><table class=\"wrapped confluenceTable\"><colgroup><col><col><col><col></colgroup><tbody><tr><th class=\"confluenceTh\"><p><span style=\"color: rgb(0,0,0);\">是否必选</span></p></th><th class=\"confluenceTh\"><p><span style=\"color: rgb(0,0,0);\">参数名</span></p></th><th class=\"confluenceTh\"><p><span style=\"color: rgb(0,0,0);\">类型</span></p></th><th class=\"confluenceTh\"><p><span style=\"color: rgb(0,0,0);\">参数说明</span></p></th></tr><tr><td class=\"confluenceTd\"><p><span style=\"color: rgb(0,0,0);\">必选</span></p></td><td class=\"confluenceTd\"><p><span style=\"color: rgb(0,0,0);\">api_key</span></p></td><td class=\"confluenceTd\"><p><span style=\"color: rgb(0,0,0);\">String</span></p></td><td class=\"confluenceTd\"><p><span style=\"color: rgb(0,0,0);\">调用此 API 的 API Key</span></p></td></tr><tr><td class=\"confluenceTd\"><p><span style=\"color: rgb(0,0,0);\">必选</span></p></td><td class=\"confluenceTd\"><p><span style=\"color: rgb(0,0,0);\">api_secret</span></p></td><td class=\"confluenceTd\"><p><span style=\"color: rgb(0,0,0);\">String</span></p></td><td class=\"confluenceTd\"><p><span style=\"color: rgb(0,0,0);\">调用此 API 的 API Secret</span></p></td></tr><tr><td class=\"confluenceTd\"><span style=\"color: rgb(0,0,0);\">可选</span></td><td class=\"confluenceTd\"><span style=\"color: rgb(0,0,0);\">display_name</span></td><td class=\"confluenceTd\"><span style=\"color: rgb(0,0,0);\">String</span></td><td class=\"confluenceTd\"><span style=\"color: rgb(0,0,0);\">人脸集合的名字，最长<span class=\"inline-comment-marker\" data-ref=\"9f098728-ac30-41a2-aab6-05b79f8a7d2e\">256</span>个字符，不能包括字符^@,&amp;=*'\"</span></td></tr><tr><td colspan=\"1\" class=\"confluenceTd\"><span style=\"color: rgb(0,0,0);\">可选</span></td><td colspan=\"1\" class=\"confluenceTd\"><span style=\"color: rgb(0,0,0);\">outer_id</span></td><td colspan=\"1\" class=\"confluenceTd\"><span style=\"color: rgb(0,0,0);\">String</span></td><td colspan=\"1\" class=\"confluenceTd\"><span style=\"color: rgb(0,0,0);\">账号下全局唯一的 FaceSet 自定义标识，可以用来管理 FaceSet 对象。最长255个字符，<span class=\"inline-comment-marker\" data-ref=\"63fc0fd1-cd44-4256-bab5-971a939d66e2\"><span class=\"inline-comment-marker\" data-ref=\"183dcb11-c22c-47f4-aa9c-2ba6f3c8210c\">不能包括字符^@,&amp;=*'\"</span></span></span></td></tr><tr><td colspan=\"1\" class=\"confluenceTd\"><span style=\"color: rgb(0,0,0);\">可选</span></td><td colspan=\"1\" class=\"confluenceTd\"><span style=\"color: rgb(0,0,0);\">tags</span></td><td colspan=\"1\" class=\"confluenceTd\"><span style=\"color: rgb(0,0,0);\">String</span></td><td colspan=\"1\" class=\"confluenceTd\"><span style=\"color: rgb(0,0,0);\">FaceSet 自定义标签组成的字符串，用来对 FaceSet 分组。最长<span class=\"inline-comment-marker\" data-ref=\"1be760b6-f20d-4ff3-a086-b7f763abd84d\">255</span>个字符，多个 tag 用逗号分隔，每个 tag 不能包括字符^@,&amp;=*'\"</span></td></tr><tr><td class=\"confluenceTd\"><p><span style=\"color: rgb(0,0,0);\">可选</span></p></td><td class=\"confluenceTd\"><p><span style=\"color: rgb(0,0,0);\">face_tokens</span></p></td><td class=\"confluenceTd\"><p><span style=\"color: rgb(0,0,0);\">String</span></p></td><td class=\"confluenceTd\"><p><span style=\"color: rgb(0,0,0);\">人脸标识 face_token，可以是一个或者多个，用逗号分隔。最多不超过5个 face_token</span></p></td></tr><tr><td colspan=\"1\" class=\"confluenceTd\"><span style=\"color: rgb(0,0,0);\">可选</span></td><td colspan=\"1\" class=\"confluenceTd\"><span style=\"color: rgb(0,0,0);\">user_data</span></td><td colspan=\"1\" class=\"confluenceTd\"><span style=\"color: rgb(0,0,0);\">String</span></td><td colspan=\"1\" class=\"confluenceTd\"><span style=\"color: rgb(0,0,0);\">自定义用户信息，不大于<span class=\"inline-comment-marker\" data-ref=\"f9edadb1-691d-4d80-933e-909096780f61\">16 KB，不能包括字符^@,&amp;=*'\"</span></span></td></tr><tr><td colspan=\"1\" class=\"confluenceTd\"><span style=\"color: rgb(0,0,0);\">可选</span></td><td colspan=\"1\" class=\"confluenceTd\"><span style=\"color: rgb(0,0,0);\">force_merge</span></td><td colspan=\"1\" class=\"confluenceTd\"><span style=\"color: rgb(0,0,0);\">Int</span></td><td colspan=\"1\" class=\"confluenceTd\"><p><span style=\"color: rgb(0,0,0);\">在传入 outer_id 的情况下，如果 outer_id 已经存在，是否将 face_token 加入已经存在的 FaceSet 中</span></p><p><span style=\"color: rgb(0,0,0);\">0：不将 face_tokens 加入已存在的 FaceSet 中，直接返回 FACESET_EXIST 错误</span></p><p><span style=\"color: rgb(0,0,0);\">1：将 face_tokens 加入已存在的 FaceSet 中</span></p><p><span style=\"color: rgb(0,0,0);\">默认值为0</span></p></td></tr></tbody></table></div>\"\"\")[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "76bfbaf8",
   "metadata": {},
   "outputs": [],
   "source": [
    "import requests"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "0ab5cc7d",
   "metadata": {},
   "outputs": [],
   "source": [
    "FaceSet_url = 'https://api-cn.faceplusplus.com/facepp/v3/faceset/create'\n",
    "\n",
    "\n",
    "payload = {\n",
    "    \"api_key\":API_Key,\n",
    "    \"api_secret\":API_Secret\n",
    "}\n",
    "\n",
    "r = requests.post(url=FaceSet_url,params=payload)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "e0342076",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<Response [200]>"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "f0f2527c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'faceset_token': 'df32fc323f88fb8a1f0cf5aa13ad7ef6',\n",
       " 'time_used': 181,\n",
       " 'face_count': 0,\n",
       " 'face_added': 0,\n",
       " 'request_id': '1648521274,24ab5496-ed89-4336-b568-ae21e98658d9',\n",
       " 'outer_id': '',\n",
       " 'failure_detail': []}"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r.json()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "665db8c0",
   "metadata": {},
   "source": [
    "## 查询人脸库\n",
    "* 描述\n",
    "> 1. 获取某一 API Key 下的 FaceSet 列表及其 faceset_token、outer_id、display_name 和 tags 等信息。\n",
    "> 1. 注意：2017年8月16日后，调用本接口将不会一次性返回全量的 FaceSet。单次查询最多返回 100 个 FaceSet。如需获取全量数据，需要配合使用 start 和 next 参数。请尽快修改调整您的程序。\n",
    "\n",
    "* url \n",
    "> https://api-cn.faceplusplus.com/facepp/v3/faceset/getfacesets\n",
    "\n",
    "* 调用方法\n",
    "> POST"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "657b0122",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>是否必选</th>\n",
       "      <th>参数名</th>\n",
       "      <th>类型</th>\n",
       "      <th>参数说明</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>必选</td>\n",
       "      <td>api_key</td>\n",
       "      <td>String</td>\n",
       "      <td>调用此API的API Key</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>必选</td>\n",
       "      <td>api_secret</td>\n",
       "      <td>String</td>\n",
       "      <td>调用此API的API Secret</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>可选</td>\n",
       "      <td>tags</td>\n",
       "      <td>String</td>\n",
       "      <td>包含需要查询的FaceSet标签的字符串，用逗号分隔</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>可选</td>\n",
       "      <td>start</td>\n",
       "      <td>Int</td>\n",
       "      <td>一个数字 n，表示开始返回的 faceset_token 在传入的 API Key 下的序号...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  是否必选         参数名      类型                                               参数说明\n",
       "0   必选     api_key  String                                     调用此API的API Key\n",
       "1   必选  api_secret  String                                  调用此API的API Secret\n",
       "2   可选        tags  String                         包含需要查询的FaceSet标签的字符串，用逗号分隔\n",
       "3   可选       start     Int  一个数字 n，表示开始返回的 faceset_token 在传入的 API Key 下的序号..."
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.read_html(\"\"\"<div class=\"table-wrap\"><table class=\"wrapped confluenceTable\"><colgroup><col><col><col><col></colgroup><tbody><tr><th class=\"confluenceTh\"><p><span style=\"color: rgb(0,0,0);\">是否必选</span></p></th><th class=\"confluenceTh\"><p><span style=\"color: rgb(0,0,0);\">参数名</span></p></th><th class=\"confluenceTh\"><p><span style=\"color: rgb(0,0,0);\">类型</span></p></th><th class=\"confluenceTh\"><p><span style=\"color: rgb(0,0,0);\">参数说明</span></p></th></tr><tr><td class=\"confluenceTd\"><p><span style=\"color: rgb(0,0,0);\">必选</span></p></td><td class=\"confluenceTd\"><p><span style=\"color: rgb(0,0,0);\">api_key</span></p></td><td class=\"confluenceTd\"><p><span style=\"color: rgb(0,0,0);\">String</span></p></td><td class=\"confluenceTd\"><p><span style=\"color: rgb(0,0,0);\">调用此API的API Key</span></p></td></tr><tr><td class=\"confluenceTd\"><p><span style=\"color: rgb(0,0,0);\">必选</span></p></td><td class=\"confluenceTd\"><p><span style=\"color: rgb(0,0,0);\">api_secret</span></p></td><td class=\"confluenceTd\"><p><span style=\"color: rgb(0,0,0);\">String</span></p></td><td class=\"confluenceTd\"><p><span style=\"color: rgb(0,0,0);\">调用此API的API Secret</span></p></td></tr><tr><td colspan=\"1\" class=\"confluenceTd\"><span style=\"color: rgb(0,0,0);\">可选</span></td><td colspan=\"1\" class=\"confluenceTd\"><span style=\"color: rgb(0,0,0);\">tags</span></td><td colspan=\"1\" class=\"confluenceTd\"><span style=\"color: rgb(0,0,0);\">String</span></td><td colspan=\"1\" class=\"confluenceTd\"><span style=\"color: rgb(0,0,0);\">包含需要查询的FaceSet标签的字符串，用逗号分隔</span></td></tr><tr><td colspan=\"1\" class=\"confluenceTd\"><span style=\"color: rgb(0,0,0);\">可选</span></td><td colspan=\"1\" class=\"confluenceTd\"><span style=\"color: rgb(0,0,0);\">start</span></td><td colspan=\"1\" class=\"confluenceTd\"><span style=\"color: rgb(0,0,0);\">Int</span></td><td colspan=\"1\" class=\"confluenceTd\"><p class=\"p1\"><span style=\"color: rgb(0,0,0);\">一个数字 n，表示开始返回的 faceset_token 在传入的 API Key 下的序号。</span></p><p><span style=\"color: rgb(0,0,0);\">通过传入数字 n，可以控制本 API 从第 n 个 faceset_token 开始返回。返回的 faceset_token 按照创建时间排序。每次返回<span class=\"s1\">1000</span>个<span class=\"s1\">FaceSets</span>。</span></p><p class=\"p1\"><span style=\"color: rgb(0,0,0);\">默认值为1。</span></p><p class=\"p1\"><span style=\"color: rgb(255,0,0);\">注意：2017年8月16日后，每次返回的 FaceSet 数量上限从 1000 改为 100。并且您可以输入上一次请求本 API 返回的 next 值，用以获得接下来的 100 个 faceset_token。请尽快修改调整您的程序。</span></p></td></tr></tbody></table></div>\"\"\")[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "4d74f406",
   "metadata": {},
   "outputs": [],
   "source": [
    "getfacesets_url = 'https://api-cn.faceplusplus.com/facepp/v3/faceset/getfacesets'\n",
    "\n",
    "\n",
    "payload = {\n",
    "    \"api_key\":API_Key,\n",
    "    \"api_secret\":API_Secret\n",
    "}\n",
    "\n",
    "r = requests.post(url=getfacesets_url,params=payload)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "0ace9e69",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<Response [200]>"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "4d4c8a1f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'time_used': 97,\n",
       " 'facesets': [{'faceset_token': '6aaaa11184769846b83e74b6cdd71977',\n",
       "   'outer_id': '',\n",
       "   'display_name': '测试的人脸库',\n",
       "   'tags': ''},\n",
       "  {'faceset_token': 'b0f2585396b82123689c9d55c10430fc',\n",
       "   'outer_id': '',\n",
       "   'display_name': '',\n",
       "   'tags': ''},\n",
       "  {'faceset_token': 'ecbe1fc663cc157c8084c8b50a566542',\n",
       "   'outer_id': '',\n",
       "   'display_name': '测试的人脸库',\n",
       "   'tags': ''},\n",
       "  {'faceset_token': 'ebffac65b13122b260ff2977dff65fdb',\n",
       "   'outer_id': '',\n",
       "   'display_name': '测试的人脸库',\n",
       "   'tags': ''},\n",
       "  {'faceset_token': '8df353cff4241563dd9b9d11524bfae2',\n",
       "   'outer_id': '',\n",
       "   'display_name': '测试的人脸库',\n",
       "   'tags': ''},\n",
       "  {'faceset_token': '8ffd4e7596545c462e9c41d3668431f8',\n",
       "   'outer_id': '',\n",
       "   'display_name': '测试的人脸库',\n",
       "   'tags': ''},\n",
       "  {'faceset_token': '4418d33513d0ee7e9ff2a65ebc35b6b8',\n",
       "   'outer_id': '',\n",
       "   'display_name': '测试的人脸库',\n",
       "   'tags': ''},\n",
       "  {'faceset_token': 'b5e4f35146c129b4f3d6d7e750315611',\n",
       "   'outer_id': '',\n",
       "   'display_name': '',\n",
       "   'tags': ''},\n",
       "  {'faceset_token': 'df32fc323f88fb8a1f0cf5aa13ad7ef6',\n",
       "   'outer_id': '',\n",
       "   'display_name': '',\n",
       "   'tags': ''}],\n",
       " 'request_id': '1648521550,30b218d6-8865-4fb6-a0ed-550c358b30b9'}"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r.json()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0ae7fbfa",
   "metadata": {},
   "source": [
    "## 删除人脸库\n",
    "* 描述\n",
    "> 1. 删除一个人脸集合。\n",
    "\n",
    "* url \n",
    "> https://api-cn.faceplusplus.com/facepp/v3/faceset/delete\n",
    "\n",
    "* 调用方法\n",
    "> POST"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "52674bdc",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>是否必选</th>\n",
       "      <th>参数名</th>\n",
       "      <th>类型</th>\n",
       "      <th>参数说明</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>必选</td>\n",
       "      <td>api_key</td>\n",
       "      <td>String</td>\n",
       "      <td>调用此API的API Key</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>必选</td>\n",
       "      <td>api_secret</td>\n",
       "      <td>String</td>\n",
       "      <td>调用此API的API Secret</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>必选（二选一）</td>\n",
       "      <td>faceset_token</td>\n",
       "      <td>String</td>\n",
       "      <td>FaceSet的标识</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>必选（二选一）</td>\n",
       "      <td>outer_id</td>\n",
       "      <td>String</td>\n",
       "      <td>用户提供的FaceSet标识</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>可选</td>\n",
       "      <td>check_empty</td>\n",
       "      <td>Int</td>\n",
       "      <td>删除时是否检查FaceSet中是否存在face_token，默认值为10：不检查1：检查如果...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      是否必选            参数名      类型  \\\n",
       "0       必选        api_key  String   \n",
       "1       必选     api_secret  String   \n",
       "2  必选（二选一）  faceset_token  String   \n",
       "3  必选（二选一）       outer_id  String   \n",
       "4       可选    check_empty     Int   \n",
       "\n",
       "                                                参数说明  \n",
       "0                                     调用此API的API Key  \n",
       "1                                  调用此API的API Secret  \n",
       "2                                         FaceSet的标识  \n",
       "3                                     用户提供的FaceSet标识  \n",
       "4  删除时是否检查FaceSet中是否存在face_token，默认值为10：不检查1：检查如果...  "
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.read_html(\"\"\"<table class=\"confluenceTable\"><colgroup><col><col><col><col></colgroup><tbody><tr><th class=\"confluenceTh\"><p><span style=\"color: rgb(0,0,0);\">是否必选</span></p></th><th class=\"confluenceTh\"><p><span style=\"color: rgb(0,0,0);\">参数名</span></p></th><th class=\"confluenceTh\"><p><span style=\"color: rgb(0,0,0);\">类型</span></p></th><th class=\"confluenceTh\"><p><span style=\"color: rgb(0,0,0);\">参数说明</span></p></th></tr><tr><td class=\"confluenceTd\"><p><span style=\"color: rgb(0,0,0);\">必选</span></p></td><td class=\"confluenceTd\"><p><span style=\"color: rgb(0,0,0);\">api_key</span></p></td><td class=\"confluenceTd\"><p><span style=\"color: rgb(0,0,0);\">String</span></p></td><td class=\"confluenceTd\"><p><span style=\"color: rgb(0,0,0);\">调用此API的API Key</span></p></td></tr><tr><td class=\"confluenceTd\"><p><span style=\"color: rgb(0,0,0);\">必选</span></p></td><td class=\"confluenceTd\"><p><span style=\"color: rgb(0,0,0);\">api_secret</span></p></td><td class=\"confluenceTd\"><p><span style=\"color: rgb(0,0,0);\">String</span></p></td><td class=\"confluenceTd\"><p><span style=\"color: rgb(0,0,0);\">调用此API的API Secret</span></p></td></tr><tr><td rowspan=\"2\" class=\"confluenceTd\"><span style=\"color: rgb(0,0,0);\">必选（二选一）</span></td><td colspan=\"1\" class=\"confluenceTd\"><span style=\"color: rgb(0,0,0);\">faceset_token</span></td><td colspan=\"1\" class=\"confluenceTd\"><span style=\"color: rgb(0,0,0);\">String</span></td><td colspan=\"1\" class=\"confluenceTd\"><span style=\"color: rgb(0,0,0);\">FaceSet的标识</span></td></tr><tr><td colspan=\"1\" class=\"confluenceTd\"><span style=\"color: rgb(0,0,0);\">outer_id</span></td><td colspan=\"1\" class=\"confluenceTd\"><span style=\"color: rgb(0,0,0);\">String</span></td><td colspan=\"1\" class=\"confluenceTd\"><span style=\"color: rgb(0,0,0);\">用户提供的FaceSet标识</span></td></tr><tr><td colspan=\"1\" class=\"confluenceTd\"><span style=\"color: rgb(0,0,0);\">可选</span></td><td colspan=\"1\" class=\"confluenceTd\"><span style=\"color: rgb(0,0,0);\">check_empty</span></td><td colspan=\"1\" class=\"confluenceTd\"><span style=\"color: rgb(0,0,0);\">Int</span></td><td colspan=\"1\" class=\"confluenceTd\"><p><span style=\"color: rgb(0,0,0);\">删除时是否检查FaceSet中是否存在face_token，默认值为1</span></p><p><span style=\"color: rgb(0,0,0);\">0：不检查</span></p><p><span style=\"color: rgb(0,0,0);\">1：检查</span></p><p><span style=\"color: rgb(0,0,0);\">如果设置为1，当FaceSet中存在face_token则不能删除</span></p></td></tr></tbody></table>\"\"\")[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "id": "674a05dc",
   "metadata": {},
   "outputs": [],
   "source": [
    "delete_url = 'https://api-cn.faceplusplus.com/facepp/v3/faceset/delete'\n",
    "\n",
    "faceset_token = \"df32fc323f88fb8a1f0cf5aa13ad7ef6\"\n",
    "payload = {\n",
    "    \"api_key\":API_Key,\n",
    "    \"api_secret\":API_Secret,\n",
    "    \"faceset_token\":faceset_token\n",
    "}\n",
    "\n",
    "r = requests.post(url=delete_url,params=payload)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "id": "d88819e1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<Response [200]>"
      ]
     },
     "execution_count": 50,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "id": "1b4b3e79",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'time_used': 76,\n",
       " 'facesets': [],\n",
       " 'request_id': '1648523870,2f1424b9-138b-4d32-9bd6-3c8d4ae6eae4'}"
      ]
     },
     "execution_count": 54,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "id": "91e9ffdc",
   "metadata": {},
   "outputs": [],
   "source": [
    "getfacesets_url = 'https://api-cn.faceplusplus.com/facepp/v3/faceset/getfacesets'\n",
    "\n",
    "\n",
    "payload = {\n",
    "    \"api_key\":API_Key,\n",
    "    \"api_secret\":API_Secret\n",
    "}\n",
    "\n",
    "r = requests.post(url=getfacesets_url,params=payload)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "id": "d3bb2e69",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<Response [200]>"
      ]
     },
     "execution_count": 53,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "id": "f9946b23",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'time_used': 76,\n",
       " 'facesets': [],\n",
       " 'request_id': '1648523870,2f1424b9-138b-4d32-9bd6-3c8d4ae6eae4'}"
      ]
     },
     "execution_count": 55,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "id": "dc276f6c",
   "metadata": {},
   "outputs": [],
   "source": [
    "FaceSet_url = 'https://api-cn.faceplusplus.com/facepp/v3/faceset/create'\n",
    "\n",
    "\n",
    "\n",
    "payload = {\n",
    "    \"api_key\":API_Key,\n",
    "    \"api_secret\":API_Secret,\n",
    "    \"outer_id\":'NFUSTH32-309',\n",
    "    \"display_name\":'南方学院学生32栋宿舍楼309号房',\n",
    "    \"user_data\":'4人，4男同学，0女同学'\n",
    "}\n",
    "\n",
    "r = requests.post(url=FaceSet_url,params=payload)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "id": "3b0f905b",
   "metadata": {},
   "outputs": [],
   "source": [
    "getfacesets_url = 'https://api-cn.faceplusplus.com/facepp/v3/faceset/getfacesets'\n",
    "\n",
    "\n",
    "payload = {\n",
    "    \"api_key\":API_Key,\n",
    "    \"api_secret\":API_Secret\n",
    "}\n",
    "\n",
    "r = requests.post(url=getfacesets_url,params=payload)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "id": "0e18a441",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<Response [200]>"
      ]
     },
     "execution_count": 58,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "id": "9529c010",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'time_used': 75,\n",
       " 'facesets': [{'faceset_token': '878763abdf452076ac377cf6e4bc68a6',\n",
       "   'outer_id': 'NFUSTH32-309',\n",
       "   'display_name': '南方学院学生32栋宿舍楼309号房',\n",
       "   'tags': ''}],\n",
       " 'request_id': '1648524446,bd5bb22d-dd93-464e-babd-69ad82422bc0'}"
      ]
     },
     "execution_count": 59,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r.json()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f0bf8bbb",
   "metadata": {},
   "source": [
    "## 获取人脸库信息 API\n",
    "* 描述\n",
    "> 1. 获取一个 FaceSet 的所有信息，包括此 FaceSet 的 faceset_token, outer_id, display_name 的信息，以及此 FaceSet 中存放的 face_token 数量与列表。\n",
    "> 2.注意：2017年8月16日后，调用本接口将不会一次性返回全部的 face_token 列表。单次查询最多返回 100 个 face_token。如需获取全量数据，需要配合使用 start 和 next 参数。请尽快修改调整您的程序。\n",
    "\n",
    "* url \n",
    "> https://api-cn.faceplusplus.com/facepp/v3/faceset/getdetail\n",
    "\n",
    "* 调用方法\n",
    "> POST"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "id": "12dc4455",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>是否必选</th>\n",
       "      <th>参数名</th>\n",
       "      <th>类型</th>\n",
       "      <th>参数说明</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>必选</td>\n",
       "      <td>api_key</td>\n",
       "      <td>String</td>\n",
       "      <td>调用此API的API Key</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>必选</td>\n",
       "      <td>api_secret</td>\n",
       "      <td>String</td>\n",
       "      <td>调用此API的API Secret</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>必选(二选一)</td>\n",
       "      <td>faceset_token</td>\n",
       "      <td>String</td>\n",
       "      <td>FaceSet的标识</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>必选(二选一)</td>\n",
       "      <td>outer_id</td>\n",
       "      <td>String</td>\n",
       "      <td>用户提供的FaceSet标识</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>可选（2017年8月16日起可使用）</td>\n",
       "      <td>start</td>\n",
       "      <td>Int</td>\n",
       "      <td>一个数字 n，表示开始返回的 face_token 在本 FaceSet 中的序号， n 是...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                 是否必选            参数名      类型  \\\n",
       "0                  必选        api_key  String   \n",
       "1                  必选     api_secret  String   \n",
       "2             必选(二选一)  faceset_token  String   \n",
       "3             必选(二选一)       outer_id  String   \n",
       "4  可选（2017年8月16日起可使用）          start     Int   \n",
       "\n",
       "                                                参数说明  \n",
       "0                                     调用此API的API Key  \n",
       "1                                  调用此API的API Secret  \n",
       "2                                         FaceSet的标识  \n",
       "3                                     用户提供的FaceSet标识  \n",
       "4  一个数字 n，表示开始返回的 face_token 在本 FaceSet 中的序号， n 是...  "
      ]
     },
     "execution_count": 60,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.read_html(\"\"\"<table class=\"wrapped confluenceTable\"><colgroup><col><col><col><col></colgroup><tbody><tr><th class=\"confluenceTh\"><p><span style=\"color: rgb(0,0,0);\">是否必选</span></p></th><th class=\"confluenceTh\"><p><span style=\"color: rgb(0,0,0);\">参数名</span></p></th><th class=\"confluenceTh\"><p><span style=\"color: rgb(0,0,0);\">类型</span></p></th><th class=\"confluenceTh\"><p><span style=\"color: rgb(0,0,0);\">参数说明</span></p></th></tr><tr><td class=\"confluenceTd\"><p><span style=\"color: rgb(0,0,0);\">必选</span></p></td><td class=\"confluenceTd\"><p><span style=\"color: rgb(0,0,0);\">api_key</span></p></td><td class=\"confluenceTd\"><p><span style=\"color: rgb(0,0,0);\">String</span></p></td><td class=\"confluenceTd\"><p><span style=\"color: rgb(0,0,0);\">调用此API的API Key</span></p></td></tr><tr><td class=\"confluenceTd\"><p><span style=\"color: rgb(0,0,0);\">必选</span></p></td><td class=\"confluenceTd\"><p><span style=\"color: rgb(0,0,0);\">api_secret</span></p></td><td class=\"confluenceTd\"><p><span style=\"color: rgb(0,0,0);\">String</span></p></td><td class=\"confluenceTd\"><p><span style=\"color: rgb(0,0,0);\">调用此API的API Secret</span></p></td></tr><tr><td rowspan=\"2\" class=\"confluenceTd\"><span style=\"color: rgb(0,0,0);\">必选(二选一)</span></td><td colspan=\"1\" class=\"confluenceTd\"><span style=\"color: rgb(0,0,0);\">faceset_token</span></td><td colspan=\"1\" class=\"confluenceTd\"><span style=\"color: rgb(0,0,0);\">String</span></td><td colspan=\"1\" class=\"confluenceTd\"><span style=\"color: rgb(0,0,0);\">FaceSet的标识</span></td></tr><tr><td colspan=\"1\" class=\"confluenceTd\"><span style=\"color: rgb(0,0,0);\">outer_id</span></td><td colspan=\"1\" class=\"confluenceTd\"><span style=\"color: rgb(0,0,0);\">String</span></td><td colspan=\"1\" class=\"confluenceTd\"><span style=\"color: rgb(0,0,0);\">用户提供的FaceSet标识</span></td></tr><tr><td class=\"confluenceTd\"><p><span style=\"color: rgb(0,0,0);\">可选</span></p><p><span style=\"color: rgb(0,0,0);\">（2017年8月16日起可使用）</span></p></td><td colspan=\"1\" class=\"confluenceTd\"><span style=\"color: rgb(0,0,0);\">start</span></td><td colspan=\"1\" class=\"confluenceTd\"><span style=\"color: rgb(0,0,0);\">Int</span></td><td colspan=\"1\" class=\"confluenceTd\"><p class=\"p1\"><span style=\"color: rgb(0,0,0);\">一个数字 n，表示开始返回的 face_token 在本 FaceSet 中的序号， n 是 [1,10000] 间的一个整数。 </span></p><p class=\"p1\"><span style=\"color: rgb(0,0,0);\">通过传入数字 n，可以控制本 API 从第 n 个 <span class=\"s1\">face_token </span>开始返回。返回的 face_token 按照创建时间排序，每次返回 <span class=\"s1\">100 </span>个 <span class=\"s1\">face_token</span>。</span></p><p class=\"p1\"><span style=\"color: rgb(0,0,0);\">默认值为 1。</span></p><p class=\"p1\"><span style=\"color: rgb(0,0,0);\">您可以输入上一次请求本 API 返回的 next 值，用以获得接下来的 100 个 face_token。</span></p></td></tr></tbody></table>\"\"\")[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "id": "3d56feeb",
   "metadata": {},
   "outputs": [],
   "source": [
    "getdetail_url = 'https://api-cn.faceplusplus.com/facepp/v3/faceset/getdetail'\n",
    "\n",
    "\n",
    "payload = {\n",
    "    \"api_key\":API_Key,\n",
    "    \"api_secret\":API_Secret,\n",
    "    \"faceset_token\":'878763abdf452076ac377cf6e4bc68a6'\n",
    "}\n",
    "\n",
    "r = requests.post(url=getdetail_url,params=payload)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "id": "451422c1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<Response [200]>"
      ]
     },
     "execution_count": 64,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "id": "02b492d7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'faceset_token': '878763abdf452076ac377cf6e4bc68a6',\n",
       " 'tags': '',\n",
       " 'time_used': 163,\n",
       " 'user_data': '4人，4男同学，0女同学',\n",
       " 'display_name': '南方学院学生32栋宿舍楼309号房',\n",
       " 'face_tokens': [],\n",
       " 'face_count': 0,\n",
       " 'request_id': '1648524885,b7635170-0e7b-48cd-b173-3940139a6344',\n",
       " 'outer_id': 'NFUSTH32-309'}"
      ]
     },
     "execution_count": 65,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r.json()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4f496c44",
   "metadata": {},
   "source": [
    "## 添加人脸 API\n",
    "* 描述\n",
    "> 1. 为一个已经创建的 FaceSet 添加人脸标识 face_token。一个 FaceSet 最多存储1,000个 face_token。\n",
    "> 2. 注意：2017年8月16日后，一个 FaceSet 能够存储的 face_token 数量将从 1000 提升至 10000。\n",
    "\n",
    "* url \n",
    "> https://api-cn.faceplusplus.com/facepp/v3/faceset/addface\n",
    "\n",
    "* 调用方法\n",
    "> POST"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "id": "7f020dc4",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>是否必选</th>\n",
       "      <th>参数名</th>\n",
       "      <th>类型</th>\n",
       "      <th>参数说明</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>必选</td>\n",
       "      <td>api_key</td>\n",
       "      <td>String</td>\n",
       "      <td>调用此API的API Key</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>必选</td>\n",
       "      <td>api_secret</td>\n",
       "      <td>String</td>\n",
       "      <td>调用此API的API Secret</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>必选（二选一）</td>\n",
       "      <td>faceset_token</td>\n",
       "      <td>String</td>\n",
       "      <td>FaceSet 的标识</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>必选（二选一）</td>\n",
       "      <td>outer_id</td>\n",
       "      <td>String</td>\n",
       "      <td>用户提供的 FaceSet 标识</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>必选</td>\n",
       "      <td>face_tokens</td>\n",
       "      <td>String</td>\n",
       "      <td>人脸标识 face_token 组成的字符串，可以是一个或者多个，用逗号分隔。最多不超过5个...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      是否必选            参数名      类型  \\\n",
       "0       必选        api_key  String   \n",
       "1       必选     api_secret  String   \n",
       "2  必选（二选一）  faceset_token  String   \n",
       "3  必选（二选一）       outer_id  String   \n",
       "4       必选    face_tokens  String   \n",
       "\n",
       "                                                参数说明  \n",
       "0                                     调用此API的API Key  \n",
       "1                                  调用此API的API Secret  \n",
       "2                                        FaceSet 的标识  \n",
       "3                                   用户提供的 FaceSet 标识  \n",
       "4  人脸标识 face_token 组成的字符串，可以是一个或者多个，用逗号分隔。最多不超过5个...  "
      ]
     },
     "execution_count": 66,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.read_html(\"\"\"<table class=\"relative-table wrapped confluenceTable\" style=\"width: 56.63%;\"><colgroup><col style=\"width: 13.02%;\"><col style=\"width: 11.62%;\"><col style=\"width: 6.26%;\"><col style=\"width: 69.03%;\"></colgroup><tbody><tr><th class=\"confluenceTh\"><p><span style=\"color: rgb(0,0,0);\">是否必选</span></p></th><th class=\"confluenceTh\"><p><span style=\"color: rgb(0,0,0);\">参数名</span></p></th><th class=\"confluenceTh\"><p><span style=\"color: rgb(0,0,0);\">类型</span></p></th><th class=\"confluenceTh\"><p><span style=\"color: rgb(0,0,0);\">参数说明</span></p></th></tr><tr><td class=\"confluenceTd\"><p><span style=\"color: rgb(0,0,0);\">必选</span></p></td><td class=\"confluenceTd\"><p><span style=\"color: rgb(0,0,0);\">api_key</span></p></td><td class=\"confluenceTd\"><p><span style=\"color: rgb(0,0,0);\">String</span></p></td><td class=\"confluenceTd\"><p><span style=\"color: rgb(0,0,0);\">调用此API的API Key</span></p></td></tr><tr><td class=\"confluenceTd\"><p><span style=\"color: rgb(0,0,0);\">必选</span></p></td><td class=\"confluenceTd\"><p><span style=\"color: rgb(0,0,0);\">api_secret</span></p></td><td class=\"confluenceTd\"><p><span style=\"color: rgb(0,0,0);\">String</span></p></td><td class=\"confluenceTd\"><p><span style=\"color: rgb(0,0,0);\">调用此API的API Secret</span></p></td></tr><tr><td rowspan=\"2\" class=\"confluenceTd\"><span style=\"color: rgb(0,0,0);\">必选（二选一）</span></td><td class=\"confluenceTd\"><span style=\"color: rgb(0,0,0);\">faceset_token</span></td><td class=\"confluenceTd\"><span style=\"color: rgb(0,0,0);\">String</span></td><td class=\"confluenceTd\"><span style=\"color: rgb(0,0,0);\">FaceSet 的标识</span></td></tr><tr><td colspan=\"1\" class=\"confluenceTd\"><span style=\"color: rgb(0,0,0);\">outer_id</span></td><td colspan=\"1\" class=\"confluenceTd\"><span style=\"color: rgb(0,0,0);\">String</span></td><td colspan=\"1\" class=\"confluenceTd\"><span class=\"inline-comment-marker\" data-ref=\"98434de1-cd07-46a8-ae7f-313784032559\">用户提供的 FaceSet 标识</span></td></tr><tr><td class=\"confluenceTd\"><p><span style=\"color: rgb(0,0,0);\">必选</span></p></td><td class=\"confluenceTd\"><p><span style=\"color: rgb(0,0,0);\">face_tokens</span></p></td><td class=\"confluenceTd\"><p><span style=\"color: rgb(0,0,0);\">String</span></p></td><td class=\"confluenceTd\"><p><span style=\"color: rgb(0,0,0);\">人脸标识 face_token 组成的字符串，可以是一个或者多个，用逗号分隔。最多不超过5个face_token</span></p></td></tr></tbody></table>\"\"\")[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "c0dd2f71",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 调用detect函数，函数已经封装且不需密码，现在的步骤目的是为了获取人脸的face_tokens然后将其添加到faceset_token\n",
    "import detect"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "00553842",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on module detect:\n",
      "\n",
      "NAME\n",
      "    detect\n",
      "\n",
      "FUNCTIONS\n",
      "    face_detect(image_path)\n",
      "        该函数为调用Face++ face_detect接口\n",
      "\n",
      "FILE\n",
      "    c:\\users\\c嘉嘉\\desktop\\api_-ai_-ml\\week04\\detect.py\n",
      "\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(detect)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "d533f3c9",
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'request_id': '1648637863,159accd6-aef0-4890-90d0-447a857976dc',\n",
       " 'time_used': 88,\n",
       " 'faces': [{'face_token': '331b25bebd1c80c2b78ddc5d0bcd3273',\n",
       "   'face_rectangle': {'top': 98, 'left': 164, 'width': 118, 'height': 118}}],\n",
       " 'image_id': 'fwD9nHfTb9s3JIGwQOQmSA==',\n",
       " 'face_num': 1}"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "detect.face_detect('Liu_01.jpeg')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "a1c327c0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'request_id': '1648637991,6236162f-c36a-4aba-8a71-2c90eac48ca9',\n",
       " 'time_used': 204,\n",
       " 'faces': [{'face_token': '599dce9a2bd758891d9099419aef7e0f',\n",
       "   'face_rectangle': {'top': 194, 'left': 152, 'width': 269, 'height': 269}}],\n",
       " 'image_id': 'ITeevMy/njdmsMXnrVVLjg==',\n",
       " 'face_num': 1}"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "detect.face_detect('Yi_01.png')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "7aa4343b",
   "metadata": {},
   "outputs": [],
   "source": [
    "#添加人脸\n",
    "addface_url = 'https://api-cn.faceplusplus.com/facepp/v3/faceset/addface'\n",
    "\n",
    "\n",
    "payload = {\n",
    "    \"api_key\":API_Key,\n",
    "    \"api_secret\":API_Secret,\n",
    "    \"faceset_token\":'878763abdf452076ac377cf6e4bc68a6',\n",
    "    \"face_tokens\":'331b25bebd1c80c2b78ddc5d0bcd3273,599dce9a2bd758891d9099419aef7e0f'\n",
    "}\n",
    "\n",
    "r = requests.post(url=addface_url,params=payload)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "e38d075b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<Response [200]>"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "993f8a06",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'faceset_token': '878763abdf452076ac377cf6e4bc68a6',\n",
       " 'time_used': 791,\n",
       " 'face_count': 2,\n",
       " 'face_added': 2,\n",
       " 'request_id': '1648638197,b428381a-1469-4ac7-b9e4-dff6bd2f29aa',\n",
       " 'outer_id': 'NFUSTH32-309',\n",
       " 'failure_detail': []}"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "dbc6642a",
   "metadata": {},
   "outputs": [],
   "source": [
    "#查询添加人脸结果\n",
    "getdetail_url = 'https://api-cn.faceplusplus.com/facepp/v3/faceset/getdetail'\n",
    "\n",
    "\n",
    "payload = {\n",
    "    \"api_key\":API_Key,\n",
    "    \"api_secret\":API_Secret,\n",
    "    \"faceset_token\":'878763abdf452076ac377cf6e4bc68a6'\n",
    "}\n",
    "\n",
    "r = requests.post(url=getdetail_url,params=payload)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "e64c20af",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<Response [200]>"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "04c1cfc6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'faceset_token': '878763abdf452076ac377cf6e4bc68a6',\n",
       " 'tags': '',\n",
       " 'time_used': 113,\n",
       " 'user_data': '4人，4男同学，0女同学',\n",
       " 'display_name': '南方学院学生32栋宿舍楼309号房',\n",
       " 'face_tokens': ['599dce9a2bd758891d9099419aef7e0f',\n",
       "  '331b25bebd1c80c2b78ddc5d0bcd3273'],\n",
       " 'face_count': 2,\n",
       " 'request_id': '1648638232,6e504ae2-cc7b-4af7-9bba-c3cc94be08ef',\n",
       " 'outer_id': 'NFUSTH32-309'}"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "ce789aab",
   "metadata": {},
   "outputs": [],
   "source": [
    "import search"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "id": "e44de345",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on module search:\n",
      "\n",
      "NAME\n",
      "    search\n",
      "\n",
      "FUNCTIONS\n",
      "    face_search(image_path, faceset_token)\n",
      "        该函数为调用Face++ face_search人脸搜索接口\n",
      "\n",
      "FILE\n",
      "    c:\\users\\c嘉嘉\\desktop\\api_-ai_-ml\\week04\\search.py\n",
      "\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(search)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "id": "57b518ad",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'image_id': 'uwuFcFPPfmsroBMHTKhxUA==',\n",
       " 'faces': [{'face_rectangle': {'width': 81,\n",
       "    'top': 62,\n",
       "    'left': 140,\n",
       "    'height': 81},\n",
       "   'face_token': '3525b2e89316510368cd071063f2bcc8'}],\n",
       " 'time_used': 411,\n",
       " 'thresholds': {'1e-3': 62.327, '1e-5': 73.975, '1e-4': 69.101},\n",
       " 'request_id': '1648650037,13b8c75e-6379-49d2-bdff-56f1bf506063',\n",
       " 'results': [{'confidence': 91.808,\n",
       "   'user_id': '',\n",
       "   'face_token': '331b25bebd1c80c2b78ddc5d0bcd3273'}]}"
      ]
     },
     "execution_count": 48,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "search.face_search('Liu_02.jpeg','878763abdf452076ac377cf6e4bc68a6')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "id": "83483922",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 根据分析上述代码 第一个face_token为我们要识别的人脸，第二个face_token为识别出来最相似的人脸。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 82,
   "id": "ccc2689e",
   "metadata": {},
   "outputs": [],
   "source": [
    "search_result=search.face_search('Liu_02.jpeg','878763abdf452076ac377cf6e4bc68a6')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 83,
   "id": "2272cb40",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "91.808"
      ]
     },
     "execution_count": 83,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "search_result['results'][0]['confidence']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 84,
   "id": "6fa6cce2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "62.327"
      ]
     },
     "execution_count": 84,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "search_result['thresholds']['1e-3']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 85,
   "id": "fc8f0f23",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "很好\n"
     ]
    }
   ],
   "source": [
    "dict =  search_result\n",
    "if 'results' in dict:\n",
    "    print('很好')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 86,
   "id": "d25f72c5",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "欢迎您回来宿舍！当前时间： 2022-03-30 22:53:58\n"
     ]
    }
   ],
   "source": [
    "\n",
    "    if search_result['results'][0]['confidence']< search_result['thresholds']['1e-3']:\n",
    "        print('十分抱歉！您不是该宿舍成员，请联系宿舍管理员。当前时间：',time.strftime(time_format, time.localtime()) )\n",
    "    else:\n",
    "        print('欢迎您回来宿舍！当前时间：',time.strftime(time_format, time.localtime()) )\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "2d246d87",
   "metadata": {},
   "outputs": [],
   "source": [
    "import time"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "7ee6e27e",
   "metadata": {},
   "outputs": [],
   "source": [
    "time_format = '%Y-%m-%d %X'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "id": "a0220652",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'2022-03-30 20:07:00'"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "time.strftime(time_format, time.localtime())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 71,
   "id": "0fcceb3f",
   "metadata": {},
   "outputs": [],
   "source": [
    "result=\"十分抱歉！您不是该宿舍成员，请联系宿舍管理员。当前时间： \"+time.strftime(time_format, time.localtime())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 72,
   "id": "686a947d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'十分抱歉！您不是该宿舍成员，请联系宿舍管理员。当前时间： 2022-03-30 22:48:37'"
      ]
     },
     "execution_count": 72,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "result"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "76848a02",
   "metadata": {},
   "outputs": [],
   "source": [
    "import face_system"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "bd9e0b0a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on module face_system:\n",
      "\n",
      "NAME\n",
      "    face_system\n",
      "\n",
      "FUNCTIONS\n",
      "    system(image_path, outer_id)\n",
      "        该函数为宿舍人脸识别系统的封装算法，设计者：蔡洪嘉；说明：按照说明输入相关资料，系统通过运算后得出是否为宿舍成员。【图片相对地址/绝对地址,宿舍楼栋指定编号】\n",
      "\n",
      "DATA\n",
      "    __warningregistry__ = {'version': 13}\n",
      "    time_format = '%Y-%m-%d %X'\n",
      "\n",
      "FILE\n",
      "    c:\\users\\c嘉嘉\\desktop\\api_-ai_-ml\\week04\\face_system.py\n",
      "\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(face_system)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "45a68cb5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "('欢迎您回来宿舍！当前时间：', '2022-03-30 23:13:54')"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "face_system.system('Liu_02.jpeg','NFUSTH32-309')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "1d9538e0",
   "metadata": {},
   "outputs": [],
   "source": [
    "import analyze"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "e58f74a4",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on module analyze:\n",
      "\n",
      "NAME\n",
      "    analyze\n",
      "\n",
      "FUNCTIONS\n",
      "    face_analyze(face_tokens)\n",
      "        该函数为调用Face++ face_analyze接口\n",
      "\n",
      "FILE\n",
      "    c:\\users\\c嘉嘉\\desktop\\api_-ai_-ml\\week04\\宿舍人脸识别系统（测试版）\\analyze.py\n",
      "\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(analyze)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "03d47300",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'time_used': 231,\n",
       " 'request_id': '1648658046,dc02a036-4839-446b-ac4c-4166786b5b49',\n",
       " 'faces': [{'landmark': {'contour_chin': {'y': 141, 'x': 188},\n",
       "    'left_eye_upper_left_quarter': {'y': 74, 'x': 166},\n",
       "    'mouth_lower_lip_right_contour1': {'y': 118, 'x': 196},\n",
       "    'left_eye_bottom': {'y': 79, 'x': 170},\n",
       "    'mouth_lower_lip_right_contour2': {'y': 120, 'x': 198},\n",
       "    'contour_left7': {'y': 106, 'x': 144},\n",
       "    'contour_left6': {'y': 100, 'x': 143},\n",
       "    'contour_left5': {'y': 95, 'x': 142},\n",
       "    'contour_left4': {'y': 89, 'x': 141},\n",
       "    'contour_left3': {'y': 83, 'x': 141},\n",
       "    'contour_left2': {'y': 77, 'x': 141},\n",
       "    'contour_left1': {'y': 71, 'x': 141},\n",
       "    'left_eye_lower_left_quarter': {'y': 78, 'x': 165},\n",
       "    'contour_right1': {'y': 73, 'x': 221},\n",
       "    'contour_right3': {'y': 83, 'x': 221},\n",
       "    'contour_right2': {'y': 78, 'x': 221},\n",
       "    'contour_right5': {'y': 93, 'x': 220},\n",
       "    'contour_right4': {'y': 88, 'x': 221},\n",
       "    'contour_right7': {'y': 103, 'x': 218},\n",
       "    'left_eyebrow_left_corner': {'y': 68, 'x': 155},\n",
       "    'right_eye_right_corner': {'y': 78, 'x': 213},\n",
       "    'nose_bridge1': {'y': 76, 'x': 190},\n",
       "    'nose_bridge3': {'y': 92, 'x': 191},\n",
       "    'nose_bridge2': {'y': 84, 'x': 190},\n",
       "    'right_eyebrow_upper_left_corner': {'y': 68, 'x': 197},\n",
       "    'mouth_upper_lip_right_contour4': {'y': 117, 'x': 196},\n",
       "    'mouth_upper_lip_right_contour1': {'y': 114, 'x': 193},\n",
       "    'right_eye_left_corner': {'y': 79, 'x': 198},\n",
       "    'left_eyebrow_upper_right_corner': {'y': 67, 'x': 182},\n",
       "    'left_eyebrow_upper_middle': {'y': 63, 'x': 168},\n",
       "    'mouth_lower_lip_right_contour3': {'y': 122, 'x': 194},\n",
       "    'nose_left_contour3': {'y': 101, 'x': 177},\n",
       "    'mouth_lower_lip_bottom': {'y': 122, 'x': 189},\n",
       "    'mouth_upper_lip_right_contour2': {'y': 115, 'x': 198},\n",
       "    'left_eye_top': {'y': 73, 'x': 170},\n",
       "    'nose_left_contour1': {'y': 78, 'x': 183},\n",
       "    'mouth_upper_lip_bottom': {'y': 118, 'x': 189},\n",
       "    'mouth_upper_lip_left_contour2': {'y': 115, 'x': 180},\n",
       "    'mouth_upper_lip_top': {'y': 115, 'x': 189},\n",
       "    'mouth_upper_lip_left_contour1': {'y': 114, 'x': 186},\n",
       "    'mouth_upper_lip_left_contour4': {'y': 117, 'x': 182},\n",
       "    'right_eye_top': {'y': 75, 'x': 205},\n",
       "    'mouth_upper_lip_right_contour3': {'y': 117, 'x': 200},\n",
       "    'right_eye_bottom': {'y': 81, 'x': 206},\n",
       "    'right_eyebrow_lower_left_corner': {'y': 71, 'x': 197},\n",
       "    'mouth_left_corner': {'y': 117, 'x': 174},\n",
       "    'nose_middle_contour': {'y': 106, 'x': 190},\n",
       "    'right_eye_lower_right_quarter': {'y': 80, 'x': 210},\n",
       "    'right_eyebrow_lower_right_quarter': {'y': 69, 'x': 214},\n",
       "    'contour_right9': {'y': 113, 'x': 215},\n",
       "    'mouth_right_corner': {'y': 117, 'x': 202},\n",
       "    'right_eye_lower_left_quarter': {'y': 80, 'x': 202},\n",
       "    'right_eye_center': {'y': 78, 'x': 205},\n",
       "    'left_eye_upper_right_quarter': {'y': 75, 'x': 175},\n",
       "    'right_eyebrow_lower_left_quarter': {'y': 70, 'x': 203},\n",
       "    'left_eye_pupil': {'y': 76, 'x': 170},\n",
       "    'contour_right8': {'y': 108, 'x': 217},\n",
       "    'contour_left13': {'y': 134, 'x': 164},\n",
       "    'left_eyebrow_lower_right_quarter': {'y': 69, 'x': 175},\n",
       "    'left_eye_right_corner': {'y': 78, 'x': 178},\n",
       "    'left_eyebrow_lower_right_corner': {'y': 70, 'x': 181},\n",
       "    'mouth_upper_lip_left_contour3': {'y': 117, 'x': 176},\n",
       "    'left_eyebrow_lower_left_quarter': {'y': 68, 'x': 161},\n",
       "    'mouth_lower_lip_left_contour1': {'y': 118, 'x': 182},\n",
       "    'mouth_lower_lip_left_contour3': {'y': 122, 'x': 184},\n",
       "    'mouth_lower_lip_left_contour2': {'y': 120, 'x': 179},\n",
       "    'contour_left9': {'y': 117, 'x': 149},\n",
       "    'left_eye_lower_right_quarter': {'y': 79, 'x': 174},\n",
       "    'contour_right6': {'y': 98, 'x': 219},\n",
       "    'nose_tip': {'y': 99, 'x': 192},\n",
       "    'right_eyebrow_upper_middle': {'y': 65, 'x': 209},\n",
       "    'right_eyebrow_lower_middle': {'y': 69, 'x': 209},\n",
       "    'left_eye_center': {'y': 76, 'x': 170},\n",
       "    'right_eyebrow_upper_left_quarter': {'y': 66, 'x': 203},\n",
       "    'right_eyebrow_right_corner': {'y': 70, 'x': 219},\n",
       "    'right_eyebrow_upper_right_quarter': {'y': 66, 'x': 215},\n",
       "    'contour_left16': {'y': 141, 'x': 182},\n",
       "    'contour_left15': {'y': 140, 'x': 175},\n",
       "    'contour_left14': {'y': 137, 'x': 170},\n",
       "    'left_eyebrow_upper_right_quarter': {'y': 64, 'x': 175},\n",
       "    'contour_left12': {'y': 130, 'x': 160},\n",
       "    'contour_left11': {'y': 126, 'x': 155},\n",
       "    'contour_left10': {'y': 122, 'x': 152},\n",
       "    'left_eyebrow_lower_middle': {'y': 68, 'x': 168},\n",
       "    'left_eyebrow_upper_left_quarter': {'y': 64, 'x': 161},\n",
       "    'right_eye_upper_right_quarter': {'y': 76, 'x': 210},\n",
       "    'nose_right_contour4': {'y': 104, 'x': 197},\n",
       "    'nose_right_contour5': {'y': 105, 'x': 194},\n",
       "    'nose_left_contour4': {'y': 103, 'x': 181},\n",
       "    'nose_left_contour5': {'y': 104, 'x': 185},\n",
       "    'nose_left_contour2': {'y': 94, 'x': 180},\n",
       "    'nose_right_contour1': {'y': 79, 'x': 195},\n",
       "    'nose_right_contour2': {'y': 95, 'x': 198},\n",
       "    'nose_right_contour3': {'y': 101, 'x': 200},\n",
       "    'left_eye_left_corner': {'y': 77, 'x': 162},\n",
       "    'contour_right15': {'y': 138, 'x': 199},\n",
       "    'contour_right14': {'y': 134, 'x': 202},\n",
       "    'contour_right16': {'y': 140, 'x': 194},\n",
       "    'contour_right11': {'y': 122, 'x': 211},\n",
       "    'contour_right10': {'y': 118, 'x': 213},\n",
       "    'contour_right13': {'y': 130, 'x': 206},\n",
       "    'contour_right12': {'y': 126, 'x': 209},\n",
       "    'contour_left8': {'y': 112, 'x': 146},\n",
       "    'mouth_lower_lip_top': {'y': 118, 'x': 189},\n",
       "    'right_eye_upper_left_quarter': {'y': 76, 'x': 201},\n",
       "    'right_eye_pupil': {'y': 78, 'x': 205}},\n",
       "   'attributes': {'emotion': {'sadness': 0.001,\n",
       "     'neutral': 99.997,\n",
       "     'disgust': 0.0,\n",
       "     'anger': 0.0,\n",
       "     'surprise': 0.0,\n",
       "     'fear': 0.0,\n",
       "     'happiness': 0.002},\n",
       "    'beauty': {'female_score': 75.961, 'male_score': 74.228},\n",
       "    'gender': {'value': 'Male'},\n",
       "    'age': {'value': 48},\n",
       "    'mouthstatus': {'close': 100.0,\n",
       "     'surgical_mask_or_respirator': 0.0,\n",
       "     'open': 0.0,\n",
       "     'other_occlusion': 0.0},\n",
       "    'glass': {'value': 'None'},\n",
       "    'skinstatus': {'dark_circle': 1.683,\n",
       "     'stain': 2.436,\n",
       "     'acne': 0.936,\n",
       "     'health': 69.059},\n",
       "    'headpose': {'yaw_angle': -13.94044,\n",
       "     'pitch_angle': 7.2141237,\n",
       "     'roll_angle': 5.008605},\n",
       "    'blur': {'blurness': {'threshold': 50.0, 'value': 0.188},\n",
       "     'motionblur': {'threshold': 50.0, 'value': 0.188},\n",
       "     'gaussianblur': {'threshold': 50.0, 'value': 0.188}},\n",
       "    'smile': {'threshold': 50.0, 'value': 0.1},\n",
       "    'eyestatus': {'left_eye_status': {'normal_glass_eye_open': 0.025,\n",
       "      'no_glass_eye_close': 0.0,\n",
       "      'occlusion': 0.0,\n",
       "      'no_glass_eye_open': 99.975,\n",
       "      'normal_glass_eye_close': 0.0,\n",
       "      'dark_glasses': 0.0},\n",
       "     'right_eye_status': {'normal_glass_eye_open': 0.002,\n",
       "      'no_glass_eye_close': 0.0,\n",
       "      'occlusion': 0.0,\n",
       "      'no_glass_eye_open': 99.997,\n",
       "      'normal_glass_eye_close': 0.0,\n",
       "      'dark_glasses': 0.0}},\n",
       "    'facequality': {'threshold': 70.1, 'value': 59.706},\n",
       "    'eyegaze': {'right_eye_gaze': {'position_x_coordinate': 0.506,\n",
       "      'vector_z_component': 0.976,\n",
       "      'vector_x_component': -0.207,\n",
       "      'vector_y_component': -0.061,\n",
       "      'position_y_coordinate': 0.403},\n",
       "     'left_eye_gaze': {'position_x_coordinate': 0.503,\n",
       "      'vector_z_component': 0.999,\n",
       "      'vector_x_component': 0.037,\n",
       "      'vector_y_component': 0.009,\n",
       "      'position_y_coordinate': 0.457}}},\n",
       "   'face_rectangle': {'width': 81, 'top': 62, 'left': 140, 'height': 81},\n",
       "   'face_token': '3525b2e89316510368cd071063f2bcc8'}]}"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "analyze.face_analyze('3525b2e89316510368cd071063f2bcc8')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "a99947d7",
   "metadata": {},
   "outputs": [],
   "source": [
    "import compare"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "76100a3c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on module compare:\n",
      "\n",
      "NAME\n",
      "    compare\n",
      "\n",
      "FUNCTIONS\n",
      "    face_compare(image_path1, image_path2)\n",
      "        该函数为调用Face++ face_compare接口\n",
      "\n",
      "FILE\n",
      "    c:\\users\\c嘉嘉\\desktop\\api_-ai_-ml\\week04\\宿舍人脸识别系统（测试版）\\compare.py\n",
      "\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(compare)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "4a0570b9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'request_id': '1648658179,e0002345-2710-444f-8363-d1551cf55c8a',\n",
       " 'time_used': 291,\n",
       " 'confidence': 91.747,\n",
       " 'thresholds': {'1e-3': 62.327, '1e-4': 69.101, '1e-5': 73.975},\n",
       " 'faces1': [{'face_token': 'ed596c6d8ca75d855d4cbb8115d21fff',\n",
       "   'face_rectangle': {'top': 98, 'left': 164, 'width': 118, 'height': 118}}],\n",
       " 'faces2': [{'face_token': '0de61ad0f4c6c7fb0170d6b17127fcc2',\n",
       "   'face_rectangle': {'top': 62, 'left': 140, 'width': 81, 'height': 81}}],\n",
       " 'image_id1': 'fwD9nHfTb9s3JIGwQOQmSA==',\n",
       " 'image_id2': 'uwuFcFPPfmsroBMHTKhxUA=='}"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "compare.face_compare('Liu_01.jpeg', 'Liu_02.jpeg')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "cb6185ad",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
